package demo.rbac.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import demo.rbac.dao.UserDao;
import demo.rbac.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService {

  @Autowired
  private UserDao userDao;

  /**
   * 根据用户名查找用户对象
   */
  public User findByName(String username) {
    User user = userDao.selectOne(new LambdaQueryWrapper<User>()
        .eq(User::getUsername, username)
    );
    return user;
  }

  /**
   * 根据用户id查找其拥有的角色名称
   */
  public List<String> getRolesByUserId(Long id) {
    return userDao.getRolesByUserId(id);
  }

  /**
   * 根据用户id查找其拥有的权限码
   */
  public List<String> getPermissionCodesByUserId(Long id) {
    return userDao.getPermissionCodesByUserId(id);
  }

}
